<html xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<body>
<form id="communityUserForm"  role="form" method="post" action="communityUser/save">
    <div class="form-group" >
        <label for="nickName">用户的真实姓名:</label>
        <input type="text" class="form-control" name="nickName" id="nickName"  placeholder="请输入用户的真实姓名" />
    </div>
    <div class="form-group">
        <label for="login">用户登陆账号:</label>
        <input type="text" class="form-control" name="login" id="login"  placeholder="请输入用户登陆账号" />
    </div>
    <div class="form-group">
        <label for="password">用户密码:</label>
        <input type="text" class="form-control" name="password" id="password"  placeholder="请输入用户密码" />
    </div>
    <div class="form-group" >
        <label for="state">用户状态:</label>
        <input type="text" class="form-control" name="state" id="state"  placeholder="请输入用户状态" />
    </div>
    <div class="form-group">
        <label for="userType">用户类型:</label>
        <input type="text" class="form-control" name="userType" id="userType"   placeholder="请输入用户类型" />
    </div>


</form>
<script th:inline="javascript">
    <![CDATA[
    $(function () {
        $('#communityUserForm', window.top.document).bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                nickName: {
                    validators: {
                        notEmpty: {
                            message: '真实姓名不能为空'
                        }
                    }
                },
                state: {
                    validators: {
                        notEmpty: {
                            message: '用户状态不能为空'
                        }
                    }
                },
                userType: {
                    validators: {
                        notEmpty: {
                            message: '用户类型不能为空'
                        }
                    }
                },
                login: {
                    validators: {
                        notEmpty: {
                            message: '登入账号不能为空'
                        }
                    }
                },
                password: {
                    validators: {
                        notEmpty: {
                            message: '登入密码不能为空'
                        }
                    }
                }
            }
        })

        // 绑定dialog的确定按钮的监听事件
      $("#btnOk",window.top.document).click(function() {
            $("#btnOk",window.top.document).attr("disabled",true);
        /*    // 此段是为防止需要点击两次按钮来实现验证的方法，若不添加此处的放行，那么我们将要点击两次确定按钮才可以提交验证
            var code = $("#code",window.top.document).val();*/
            // 判断当前的code又值，且当前不存在错误验证方可放开该字段的验证
           /* if(code != null && code != ""&&$("#code", window.top.document).parent("div").find('.glyphicon-remove').length==0){
                $('#communityUserForm',window.top.document).bootstrapValidator('enableFieldValidators', 'code', false);
            } else {
                $('#communityUserForm',window.top.document).bootstrapValidator('enableFieldValidators', 'code', true);
            }*/
            var bootstrapValidator = $("#communityUserForm", window.top.document).data('bootstrapValidator');
            bootstrapValidator.validate();
            if(bootstrapValidator.isValid()){
                $.post($("#communityUserForm",window.top.document).attr('action'),$("#communityUserForm",window.top.document).serialize(),function(e){
                    if(e.result){
                        refreshDoQuery();
                        window.Ewin.alert({message:'增加数据成功!'});
                    }else{
                        window.Ewin.alert({message:'增加数据失败!'});
                    }
                    $("#btnOk",window.top.document).attr("disabled",false);
                })
            }else{
                $("#btnOk",window.top.document).attr("disabled",false);
            }
        });

        // 重新刷新当前查询页的数据
        function refreshDoQuery(){
            var iframes = $(window.parent.document).contents().find(".J_iframe");
            for(var i=0;i<iframes.length;i++){
                if($(iframes[i]).css("display")=='inline'){
                    $('.modal-dialog', window.top.document).parent('div').remove()
                    $('body', window.top.document).find('.modal-backdrop').remove();
                    iframes[i].contentWindow.doQuery();
                    break;
                }
            }
        }
    })
    ]]>
</script>
</body>
</html>